package com.hunttown.mes.convert;

import com.google.common.collect.Lists;
import com.hunttown.mes.common.utils.BeanUtils;
import com.hunttown.mes.domain.TransportApiApplyThirdparty;
import com.hunttown.mes.rpc.exception.ConvertException;
import com.hunttown.mes.rpc.domain.TransportApiApplyThirdpartyDTO;
import com.hunttown.mes.rpc.domain.enums.ErrorCode;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.List;

/**
 * created by wangjunfu on 2022-04-10 09:48:00
 */
public class TransportApiApplyThirdpartyConverts {

    private static Logger LOG = LoggerFactory.getLogger(TransportApiApplyThirdpartyConverts.class);

    public static List<TransportApiApplyThirdpartyDTO> convert(List<TransportApiApplyThirdparty> transportApiApplyThirdpartyList) {
        if (CollectionUtils.isEmpty(transportApiApplyThirdpartyList)) {
            return Collections.EMPTY_LIST;
        }

        List<TransportApiApplyThirdpartyDTO> transportApiApplyThirdpartyListResult = Lists.newArrayList();
        for (TransportApiApplyThirdparty transportApiApplyThirdparty : transportApiApplyThirdpartyList) {
            transportApiApplyThirdpartyListResult.add(convert(transportApiApplyThirdparty));
        }
        return transportApiApplyThirdpartyListResult;
    }

    public static TransportApiApplyThirdpartyDTO convert(TransportApiApplyThirdparty transportApiApplyThirdparty) {
        try {
            return BeanUtils.copy(transportApiApplyThirdparty, TransportApiApplyThirdpartyDTO.class);
        } catch (Exception e) {
            LOG.error("TransportApiApplyThirdparty到TransportApiApplyThirdpartyDTO转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "TransportApiApplyThirdparty到TransportApiApplyThirdpartyDTO转换失败", e);
        }
    }

    public static TransportApiApplyThirdparty convert(TransportApiApplyThirdpartyDTO transportApiApplyThirdpartyDTO) {
        try {
            return BeanUtils.copy(transportApiApplyThirdpartyDTO, TransportApiApplyThirdparty.class);
        } catch (Exception e) {
            LOG.error("TransportApiApplyThirdpartyDTO到TransportApiApplyThirdparty转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "TransportApiApplyThirdpartyDTO到TransportApiApplyThirdparty转换失败", e);
        }
    }
}